package com.jzo2o.market.config;

import com.jzo2o.redis.properties.RedisSyncProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 线程池配置
 * @author JIAN
 */
@Configuration
public class TreadPoolConfiguration {
    @Bean("syncThreadPool")
    public ThreadPoolExecutor threadPoolExecutor(RedisSyncProperties redisSyncProperties) {
        return new ThreadPoolExecutor(
                1,
                redisSyncProperties.getQueueNum(),
                120,
                TimeUnit.SECONDS,
                new SynchronousQueue<>(),
                new ThreadPoolExecutor.DiscardPolicy()
        );
    }
}